<!--
* @author luguoxiang
* @date 2021-09-07
* 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
-->
<template>
  <t-auto-complete :options="data" highlight-keyword v-bind="$attrs" />
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { formatStr, toAsyncLoader } from '@/soar';

const props = defineProps({
  options: {
    type: [Function, String, Array],
  },
  valueField: {
    type: String,
  },
});

const data = ref([]);
toAsyncLoader(props.options)().then((res) => {
  if ('list' in res) {
    res = res.list
  }
  if (props.valueField) {
    data.value = res.map((x: object) => formatStr(props.valueField, x));
  } else {
    data.value = res;
  }
});
</script>
<script lang="ts">
export default {
  name: 'LgAutoComplete',
};
</script>
